package com.simple.upms.biz.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.simple.common.core.util.R;
import com.simple.upms.api.dto.UserInfo;
import com.simple.upms.api.entity.SysUser;
import com.simple.upms.biz.service.SysUserService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统用户控制器
 *
 * @author Administrator
 * @date 2021/01/04 13:53:29
 */
@Api(value = "user", tags = "用户管理模块")
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Resource
    private SysUserService userService;

    /**
     * 获取指定用户全部用户信息
     *
     * @param userName 用户名
     * @return {@link R} 用户信息
     */
    @GetMapping("/info/{userName}")
    public R<UserInfo> info(@PathVariable String userName) {
        SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserName, userName));
        if (sysUser == null) {
            return R.failed(StrUtil.format("用户信息为空 {}",userName));
        }
        return R.ok(userService.getUserInfo(sysUser));
    }
}
